1 using UnityEngine;
2
3 public
class DemoOwnershipGui : MonoBehaviour
4 {
5     
public GUISkin Skin;
6     
public bool TransferOwnershipOnRequest = true;
7
8     
public void OnOwnershipRequest(object[] viewAndPlayer)
9     {
10         PhotonView view = viewAndPlayer[
0] as PhotonView;
11         PhotonPlayer requestingPlayer = viewAndPlayer[
1] as PhotonPlayer;
12
13         Debug.Log(
"OnOwnershipRequest(): Player " + requestingPlayer + " requests ownership of: " + view + ".");
14         
if (this.TransferOwnershipOnRequest)
15         {
16             view.TransferOwnership(requestingPlayer.ID);
17         }
18     }
19
20
21     
#region Unity
22
23     
public void OnGUI()
24     {
25         GUI.skin =
this.Skin;
26         GUILayout.BeginArea(
new Rect(Screen.width - 200, 0, 200, Screen.height));
27         {
28             
string label = TransferOwnershipOnRequest ? "passing objects" : "rejecting to pass";
29             
if (GUILayout.Button(label))
30             {
31                 
this.TransferOwnershipOnRequest = !this.TransferOwnershipOnRequest;
32             }
33         }
34         GUILayout.EndArea();
35
36
37
38         
if (PhotonNetwork.inRoom)
39         {
40             
int playerNr = PhotonNetwork.player.ID;
41             
string playerIsMaster = PhotonNetwork.player.isMasterClient ? "(master) " : "";
42             
string playerColor = PlayerVariables.GetColorName(PhotonNetwork.player.ID);
43             GUILayout.Label(
string.Format("player {0}, {1} {2}(you)", playerNr, playerColor, playerIsMaster));
44
45             
foreach (PhotonPlayer otherPlayer in PhotonNetwork.otherPlayers)
46             {
47                 playerNr = otherPlayer.ID;
48                 playerIsMaster = otherPlayer.isMasterClient ?
"(master)" : "";
49                 playerColor = PlayerVariables.GetColorName(otherPlayer.ID);
50                 GUILayout.Label(
string.Format("player {0}, {1} {2}", playerNr, playerColor, playerIsMaster));
51             }
52
53             
if (PhotonNetwork.inRoom && PhotonNetwork.otherPlayers.Length == 0)
54             {
55                 GUILayout.Label(
"Join more clients to switch object-control.");
56             }
57         }
58         
else
59         {
60             GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
61         }
62     }
63
64     
#endregion
65 }



Trò chơi Tic-Tac-Toe, game đánh caro full source code 53.445 lượt xem

Gõ tìm kiếm nhanh...